package cn.com.css.taxInspection.common.job.task;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import cn.com.css.taxInspection.common.constants.Constants;
import cn.com.css.taxInspection.gt3.entity.JcAjxxEntity;
import cn.com.css.taxInspection.gt3.entity.JcLsfxMxEntity;
import cn.com.css.taxInspection.gt3.service.JcAjxxService;
import cn.com.css.taxInspection.gt3.service.JcLsfxMxService;
import cn.com.css.taxInspection.util.TsBqUtils;
import cn.com.css.taxInspection.workflow.service.WorkflowInspectionHearService;
import cn.com.css.taxInspection.workrisk.entity.WorkriskControlEntity;
import cn.com.css.taxInspection.workrisk.service.WorkriskControlService;
import cn.com.css.taxInspection.workrisk.service.WorkriskRisk1Service;

/**
 * 超期未下两书
 *
 * @author shaochangyang
 * @version V1.0
 * @date 2020年3月18日
 */
@Component("risk1Task7")
public class Risk1Task7 {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Resource
	private WorkflowInspectionHearService workflowInspectionHearService;

	@Resource
	private WorkriskRisk1Service workriskRisk1Service;

	@Resource
	private WorkriskControlService workriskControlService;

	@Resource
	private JcLsfxMxService jcLsfxMxService;
	
	@Resource
	private JcAjxxService jcAjxxService;
	
	public void run(String params) {
		Date date = new Date();
		LambdaQueryWrapper<JcLsfxMxEntity> queryWrapper = Wrappers.lambdaQuery();
		queryWrapper.eq(JcLsfxMxEntity::getRiskName, "超期未下两书");
		queryWrapper.eq(JcLsfxMxEntity::getYxbz, "Y");
		// TODO 排除处理中的
		
		List<JcLsfxMxEntity> list = jcLsfxMxService.list(queryWrapper);
		
		for (JcLsfxMxEntity jcLsfxMxEntity : list) {
			String relevance = jcLsfxMxEntity.getRelevance();
			String ts = jcLsfxMxEntity.getTs();
			JcAjxxEntity jcAjxxEntity = jcAjxxService.getById(relevance);
			
			if(TsBqUtils.isNotNull(ts)){
				int _i = Integer.parseInt(ts);
				if(_i >= 40 && _i <= 60){
					String jcry = jcAjxxEntity.getJcry();
					WorkriskControlEntity workriskControlEntity = new WorkriskControlEntity();
					workriskControlEntity.setId(TsBqUtils.getUUID());
					workriskControlEntity.setRelevance(relevance);
					// workriskControlEntity.setStateCode();
					// workriskControlEntity.setStateName();
					workriskControlEntity.setControlType("1");
					workriskControlEntity.setControlName("督办");
					workriskControlEntity.setControlMan1(jcry);
					workriskControlEntity.setDetails("立案40天未下两书");
					workriskControlEntity.setTaxorgcode(jcAjxxEntity.getJcbmDm());
					workriskControlEntity.setDeleted(Constants.DATA_NOT_DELETED);
					workriskControlEntity.setCreateTime(date);
					workriskControlEntity.setCreateId("sysJob");
					workriskControlService.save(workriskControlEntity);
					
				}else if(_i > 60){
					String jcry = jcAjxxEntity.getJcry();
					WorkriskControlEntity workriskControlEntity = new WorkriskControlEntity();
					workriskControlEntity.setId(TsBqUtils.getUUID());
					workriskControlEntity.setRelevance(relevance);
					// workriskControlEntity.setStateCode();
					// workriskControlEntity.setStateName();
					workriskControlEntity.setControlType("1");
					workriskControlEntity.setControlName("督办");
					workriskControlEntity.setControlMan1(jcry);
					workriskControlEntity.setDetails("立案60天未下两书");
					workriskControlEntity.setTaxorgcode(jcAjxxEntity.getJcbmDm());
					workriskControlEntity.setDeleted(Constants.DATA_NOT_DELETED);
					workriskControlEntity.setCreateTime(date);
					workriskControlEntity.setCreateId("sysJob");
					workriskControlService.save(workriskControlEntity);
					
					// TODO 
					
				}
				
			}
		}
	}

}
